export function useSaveScroll(scrollContainer: Ref<HTMLElement>) {
  const { $gsap: gsap } = useNuxtApp()

  onMounted(async () => {
    gsap.to(scrollContainer.value, {
      opacity: 1,
      duration: 0.5,
    })

    // 从本地存储读取距离顶部的值
    const storedDistanceToTop = localStorage.getItem('distanceToTop')
    if (storedDistanceToTop) {
      const distance = parseInt(storedDistanceToTop)
      // 平滑滚动到指定位置
      scrollContainer.value.scrollTo({ top: distance, behavior: 'smooth' })
    }
    scrollContainer.value.onscroll = () => {
      const distanceToTop = scrollContainer.value.scrollTop
      localStorage.setItem('distanceToTop', distanceToTop.toString())
    }
  })
}
